package com.jnu.hc.jnuhcdoccms.exception;

import com.jnu.hc.jnuhcdoccms.exception.HcAPPException;
import com.jnu.hc.jnuhcdoccms.exception.HcAppExceptionEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jnu.hc.jnuhcdoccms.dto.ResponseObject;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(HcAPPException.class)
    @ResponseBody
    public ResponseObject handleHcAppException(HcAPPException e){
        e.printStackTrace();
        System.out.println("异常信息："+e.getStackTrace());
        return new ResponseObject(e.getCode(),e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseObject handleAllException(Exception e){
        e.printStackTrace();
        System.out.println("异常信息"+e.getStackTrace()+"，内容"+e.getMessage());
        return new ResponseObject(HcAppExceptionEnum.SYSTEM_ERROR.getCode(),HcAppExceptionEnum.SYSTEM_ERROR.getMessage());
    }
}
